<script>
import { reactive, toRefs } from "vue";
import { useRouter } from "vue-router";
import { Toast } from "vant";
export default {
  setup() {
    let router = useRouter();
    const register = reactive({
      phone: "",
      password: "",
      code: "",
    });
    const submit = () => {
      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      let pass = /^[a-zA-Z0-9]\w{7,17}$/;
      if (!reg.test(register.phone) || !pass.test(register.password)) {
        //不正确处理
        Toast("请输入正确手机号码与密码");
        return;
      }else{
        Toast("注册成功");
        router.push({ path: "/my" });
      }
    };
    return {
      ...toRefs(register),
      submit,
    };
  },
};
</script>

<template>
  <div class="container register">
    <!-- 顶部 -->
    <div class="top">
      <div class="left">
        <i class="iconfont icon-zuobian"></i>
        <a @click="$router.go(-1)">返回</a>
      </div>
      <div class="center">用户注册</div>
      <div class="right">
        <i class="iconfont icon-people"></i>
        <a @click="$router.go(-1)">登录</a>
      </div>
    </div>

    <div class="content">
      <div class="logo">
        <img src="../assets/img/logo.png" alt="" />
      </div>

      <div class="resign-tit">手机号将作为登录账号</div>

      <!--设置手机号码-->
      <div class="form">
        <div class="phonenum">
          <input
            type="text"
            autocomplete="off"
            name="phone"
            placeholder="请输入手机号"
            v-model="phone"
          />
          <em></em>
        </div>

        <!-- 设置密码 -->
        <div class="get">
          <input
            type="password"
            name="phone"
            placeholder="请设置你的密码"
            v-model="password"
          />
        </div>

        <!-- 验证码 -->
        <div class="get">
          <input
            type="text"
            autocomplete="off"
            name="code"
            placeholder="请输入短信验证码"
          />
          <i></i><span>获取验证码</span>
        </div>

        <button type="button" class="login" @click="submit">注册</button>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
/* 顶部 */
.register .top {
  height: 44px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  background: linear-gradient(270deg, #7b0b3b 0%, #d51c78 100%);
  color: #fff;
  padding-right: 10px;
  padding-left: 5px;
  .center {
    font-size: 19px;
    height: 44px;
    line-height: 44px;
  }
  .left {
    display: flex;
    align-items: center;
    a {
      display: inline-block;
      font-size: 14px;
      color: #fff;
    }
    i {
      margin-right: 2px;
    }
  }
  .right {
    display: flex;
    align-items: center;
    a {
      display: inline-block;
      font-size: 14px;
      color: #fff;
    }
    i {
      margin-right: 4px;
    }
  }
}

/* 内容 */
.register .content {
  padding-left: 45px;
  padding-right: 45px;
  padding-top: 65px;
  .resign-tit {
    color: #d51c78;
    padding-top: 20px;
  }
  .logo {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 54px;
    img {
      width: 100px;
      height: 100px;
    }
  }
}
/* 短信登录 */
.register .form {
  margin-top: 20px;
  input {
    &::placeholder {
      color: #c4c4c4;
      font-size: 16px;
    }
  }
  .login {
    width: 100%;
    font-size: 18px;
    color: #fff;
    text-align: center;
    background: linear-gradient(to right, #7b0b3b, #d51c78, #7b0b3b);
    border: none;
    margin-top: 40px;
    height: 40px;
    border-radius: 20px;
    letter-spacing: 3px;
  }
}
.register .phonenum,
.register .get {
  height: 55px;
  font-size: 16px;
  border-bottom: 1px solid #f5f5f5;
}
.register .phonenum {
  display: flex;
  justify-content: space-between;
  align-items: center;
  input {
    flex: 1;
    height: 55px;
    line-height: 55px;
  }
  em {
    display: inline-block;
    background: url(../assets/img/clear.png) no-repeat;
    width: 18px;
    height: 18px;
    background-size: 100%;
  }
}
.register .get {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  input {
    flex: 1;
    height: 55px;
    width: 150px;
    line-height: 55px;
    margin-top: 2px;
  }
  i {
    display: inline-block;
    width: 1px;
    height: 20px;
    background-color: #e6e6e6;
    margin-right: 12px;
  }
  span {
    color: #d51c78;
  }
}
</style>